﻿/* 验证非空*/
function ValidateIsNull(controlID, showMsgControlID, message,result1) {
    var _controlValue = document.getElementById(controlID).value;
    if (trim(_controlValue).length == 0) {
        document.getElementById(showMsgControlID).style.visibility = 'visible';
        document.getElementById(showMsgControlID).innerText = message.toString();
        result1 = false;
    }
    else {
        document.getElementById(showMsgControlID).style.visibility = 'hidden';
        document.getElementById(showMsgControlID).innerText = "";
    }
    return result1;
}

/* 验证数字*/
function ValidateIsNumber(controlID, showMsgControlID, message, result1) {
    var _controlValue = document.getElementById(controlID).value;
    
    if (trim(_controlValue).length == 0) {
        return result1;
    }
    var _NumRg = /^\d+(\.\d+)?$/; /* 验证数字*/
    if (!_NumRg.test(_controlValue)) {
        document.getElementById(showMsgControlID).style.visibility = 'visible';
        document.getElementById(showMsgControlID).innerText = message.toString();
        result1 = false;
    }
    else {
        document.getElementById(showMsgControlID).style.visibility = 'hidden';
        document.getElementById(showMsgControlID).innerText = "";
    }
    return result1;
}

/* 验证邮件*/
function ValidateIsEmail(controlID, showMsgControlID, message, result1) {
    var _controlValue = document.getElementById(controlID).value;
    if (trim(_controlValue).length == 0) {
        return result1;
    }
    var _rg = /^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/gi; 
    if (!_rg.test(_controlValue)) {
        document.getElementById(showMsgControlID).style.visibility = 'visible';
        document.getElementById(showMsgControlID).innerText = message.toString();
        result1 = false;
    }
    else {
        document.getElementById(showMsgControlID).style.visibility = 'hidden';
        document.getElementById(showMsgControlID).innerText = "";
    }
    return result1;
}

/* 验证日期*/
function ValidateIsDate(controlID, showMsgControlID, message, result1) {
    var _controlValue = document.getElementById(controlID).value;
    if (trim(_controlValue).length == 0) {
        return result1;
    }
    var _rg = new RegExp(/^(\d{1,4})\-(\d{1,2})\-(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/); /*验证日期*/
    if (!_rg.test(_controlValue)) {
        document.getElementById(showMsgControlID).style.visibility = 'visible';
        document.getElementById(showMsgControlID).innerText = message.toString();
        result1 = false;
    }
    else {
        document.getElementById(showMsgControlID).style.visibility = 'hidden';
        document.getElementById(showMsgControlID).innerText = "";
    }
    return result1;
}

/* 验证日期*/
function ValidateIsDateNoTime(controlID, showMsgControlID, message, result1) {
    var _controlValue = document.getElementById(controlID).value;
    if (trim(_controlValue).length == 0) {
        return result1;
    }
    var _rg = new RegExp(/^\d{4}-\d{1,2}-\d{1,2}$/); /*验证日期*/
    if (!_rg.test(_controlValue)) {
        document.getElementById(showMsgControlID).style.visibility = 'visible';
        document.getElementById(showMsgControlID).innerText = message.toString();
        result1 = false;
    }
    else {
        document.getElementById(showMsgControlID).style.visibility = 'hidden';
        document.getElementById(showMsgControlID).innerText = "";
    }
    return result1;
}

/* 验证时间：15:00*/
function ValidateIsTime(controlID, showMsgControlID, message, result1) {
    var _controlValue = document.getElementById(controlID).value;
    if (trim(_controlValue).length == 0) {
        return result1;
    }
    var _rg = new RegExp(/([0-1]?[0-9]|2[0-3]):([0-5][0-9])/); /* 验证时间：15:00*/
    if (!_rg.test(_controlValue)) {
        document.getElementById(showMsgControlID).style.visibility = 'visible';
        document.getElementById(showMsgControlID).innerText = message.toString();
        result1 = false;
    }
    else {
        document.getElementById(showMsgControlID).style.visibility = 'hidden';
        document.getElementById(showMsgControlID).innerText = "";
    }
    return result1;
}

/* 比较日期大小*/
function ValidateComareDate(startControlID,endControlID, showMsgControlID, message, result1) {
    var _startControlValue = document.getElementById(startControlID).value;
    var _endControlValue = document.getElementById(endControlID).value;

    var _rg = new RegExp(/^\d{4}-\d{1,2}-\d{1,2}$/); /*验证日期*/
    if (trim(_startControlValue).length == 0) {
        return result1;
    }
     if (trim(_endControlValue).length == 0) {
        return result1;
    }

    if (!_rg.test(_startControlValue)) {

        return result1;
    }
    if (!_rg.test(_endControlValue)) {

        return result1;
    }
    var _startDate = new Date(_startControlValue.replace(/-/g, "/")); 
    var _endDate = new Date(_endControlValue.replace(/-/g, "/"));
    if (Date.parse(_startDate) - Date.parse(_endDate) > 0) {
        document.getElementById(showMsgControlID).style.visibility = 'visible';
        document.getElementById(showMsgControlID).innerText = message.toString();
        result1 = false;
    } 
    return result1;
}